function [obj2] = compute_laggedBases(Yvals, initConds, flag_YconsumerHasK2)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% This function takes initial conditions and new adoptions/exits, and returns
	% an object that also includes lagged installed bases.
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Inputs:
	% Yvals:						object
	%	.consumerAdoptions:				[T x K1 x K2 x dim3]  or [T x K1 x dim3]
	%	.providerAdoptions:				T x K x dim3
	%	.providerExits:					T x K x dim3
	% initConds:					object
	%	.laggedConsumersOrig:				K1 x 1
	%	.laggedConsumersDest:				K2 x 1
	%	.laggedProviders:					K x 1
	%	.popAtRisk:						object:
	%		.providerAdoptions:				K x 1
	%		.consumerAdoptions:				K x 1
	% flag_YconsumerHasK2:			boolean
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Outputs:
	% obj2:							object:
	%	.consumerAdoptions:				[T x K1 x K2 x dim3]  or [T x K1 x dim3]
	%	.providerAdoptions:				T x K x dim3
	%	.providerExits:					T x K x dim3
	%	.laggedConsumersOrig:				T x K1 x dim3
	%	.laggedConsumersDest:				T x K2 x dim3
	%	.laggedProviders:					T x K x dim3
	%	.popAtRisk:						object:
	%		.consumerAdoptions:				T x K x dim3
	%		.providerAdoptions:				T x K1 x dim3
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	% Copy consumerAdoptions, providerAdoptions and providerExits (new events)
	obj2.consumerAdoptions = Yvals.consumerAdoptions;
	obj2.providerAdoptions  = Yvals.providerAdoptions;
	obj2.providerExits      = Yvals.providerExits;
	
	% Deal with providers
	lagged_cumsum_providerAdoptions  = cumsum(Yvals.providerAdoptions,1) - Yvals.providerAdoptions;  % T x K x dim3;
	lagged_cumsum_providerExits      = cumsum(Yvals.providerExits,1)     - Yvals.providerExits;      % T x K x dim3;
	obj2.laggedProviders         = initConds.laggedProviders'              + lagged_cumsum_providerAdoptions - lagged_cumsum_providerExits; % T x K x dim3
	popAtRisk.providerAdoptions  = initConds.popAtRisk.providerAdoptions'  - lagged_cumsum_providerAdoptions + lagged_cumsum_providerExits; % T x K x dim3
	
	% Deal with consumers
	lagged_cumsum_consumerAdoptions = cumsum(Yvals.consumerAdoptions,1) - Yvals.consumerAdoptions; % [T x K1 x K2 x dim3] or [T x K1 x dim3]
	if flag_YconsumerHasK2 % Yvals.consumerAdoptions counts adoptions for each (k1,k2)
		[T,K1,K2,dim3] = size(lagged_cumsum_consumerAdoptions);
		lagged_cumsum_consumerAdoptions_tk1 = reshape(sum(lagged_cumsum_consumerAdoptions,3), [T K1 dim3]); % T x K1 x dim3
		lagged_cumsum_consumerAdoptions_tk2 = reshape(sum(lagged_cumsum_consumerAdoptions,2), [T K2 dim3]); % T x K2 x dim3
		obj2.laggedConsumersDest = initConds.laggedConsumersDest' + lagged_cumsum_consumerAdoptions_tk2; % T x K2 x dim3
	else  % Yvals.consumerAdoptions counts adoptions for each k1 (summed up across all k2's).
		lagged_cumsum_consumerAdoptions_tk1 = lagged_cumsum_consumerAdoptions; % T x K1 x dim3
		% Cannot computer laggedConsumersDest --> I just don't.
	end
	obj2.laggedConsumersOrig    = initConds.laggedConsumersOrig'         + lagged_cumsum_consumerAdoptions_tk1; % T x K1 x dim3
	popAtRisk.consumerAdoptions = initConds.popAtRisk.consumerAdoptions' - lagged_cumsum_consumerAdoptions_tk1; % T x K1 x dim3
	
	% Output popAtRisk
	obj2.popAtRisk = popAtRisk;
end
